<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>专属你的七夕好运来了</title>
    <meta name="description" content="点击解锁免费报告，你也快来领取吧">
    <link rel="stylesheet" href="/static/active/valentine2022/css/index.css?v=4">
</head>
<body>
<div class="container">
    {if $is_in_app}
    <div id="nav" class="nav" style="padding-top:{$h}px;">
        <div class="to-back" style="top:{$h}px;">
            <div class="img"></div>
        </div>
        <div class="title-name">专属你的七夕好运来了</div>
        {if $is_in_app}
        <!--        <div class="share-btn event-btn" data-event="share-page">分享</div>-->
        {/if}
    </div>
    {/if}
    <div class="head" style="{if $is_in_app}margin-top: {$h}px;{/if}"></div>
    <div class="body">
        {if !$is_in_app}
        <div class="area-box">
            <div class="area-title" style="top: -1.19rem;"><span class="icon icon-friend"></span><span class="title-text">为TA助力</span></div>
            <div class="area-tip" style="padding: 3.38rem 0;">
                您的好友正在邀请你帮TA助力<br/>
                查看{if $coupon_type==2}婚姻报告{elseif $coupon_type==3}合盘报告{elseif $coupon_type==1}恋爱报告{/if}～
            </div>
            <div class="zhunzhun"></div>
            <div class="btn large-btn event-btn" id="jmlink-btn" data-event="show-copy" data-code="{$code}">点击进行助力</div>
            <div style="height: 0.5rem;"></div>
        </div>
        {else}
        <div class="area-box index-box">
            <div class="title-bg"></div>
            <div class="area-title">限时签到</div>
            <div class="area-tip">首次签到，最高可享一生报告免费券</div>
            <div class="sign-progress">
                <div class="progress progress-0">
                    <div class="progress-item">
                        <div class="progress-text">1天</div>
                        <div class="progress-bg"><span class="point first"></span><span class="point"></span></div>
                        <div class="progress-img"></div>
                    </div>
                    <div class="progress-item">
                        <div class="progress-text">2天</div>
                        <div class="progress-bg"><span class="point"></span></div>
                        <div class="progress-img"></div>
                    </div>
                    <div class="progress-item">
                        <div class="progress-text">3天</div>
                        <div class="progress-bg"><span class="point"></span></div>
                        <div class="progress-img gift1"></div>
                        <div class="progress-btn event-btn" data-event="show" data-day="3">查看</div>
                    </div>
                    <div class="progress-item">
                        <div class="progress-text">4天</div>
                        <div class="progress-bg"><span class="point"></span></div>
                        <div class="progress-img"></div>
                    </div>
                    <div class="progress-item">
                        <div class="progress-text">5天</div>
                        <div class="progress-bg"><span class="point"></span></div>
                        <div class="progress-img gift2"></div>
                        <div class="progress-btn event-btn" data-event="show" data-day="5">查看</div>
                    </div>
                    <span class="big-point"></span>
                </div>
            </div>
            <div class="btn large-btn event-btn" id="sign-btn" data-event="sign">签到抽取优惠券</div>
            <div style="height: 0.5rem;"></div>
        </div>
        <div class="area-box index-box" style="background-color: #ffeef1;">
            <div class="area-title" style="top: -1.19rem;"><span class="icon icon-friend"></span><span class="title-text">好友助力拿免费报告</span>
            </div>
            <div class="item-list">
                <div class="title-list">
                    <div class="title">恋爱报告</div>
                    <div class="title">婚姻报告</div>
                    <div class="title">合盘报告</div>
                </div>
                <div class="btn-list">
                    <div class="invite-item">
                        <div class="btn small-btn event-btn" data-event="invite" data-type="0">发起助力</div>
                    </div>
                    <div class="invite-item">
                        <div class="btn small-btn event-btn" data-event="invite" data-type="1">发起助力</div>
                    </div>
                    <div class="invite-item">
                        <div class="btn small-btn event-btn" data-event="invite" data-type="2">发起助力</div>
                    </div>
                </div>
                <div class="title-list">
                    <div class="title">邀请码助力</div>
                    <div class="title"></div>
                    <div class="title"></div>
                </div>
                <div class="help">
                    <input id="code" class="input" type="text" placeholder="填写邀请码帮TA助力" autocomplete="off" value="{$code}"/>
                    <div id="help-btn" class="btn small-btn event-btn" data-event="help">帮TA助力</div>
                </div>
            </div>
        </div>
        <div class="rule-box index-box">
            <div class="rule-title"><span class="icon icon-flag"></span>活动规则</div>
            <p class="text">1、用户首次签到可选择获得恋爱报告、婚姻报告、合盘报告其中一个优惠券，获得的折扣会从88折、5折、免费券中随机发放一个。</p>
            <p class="text">2、累计签到3天及五天可解锁年运及一生报告优惠券奖励。</p>
            <p class="text">3、活动期间每人每天只有一次助力机会，并且对同一个用户不能重复助力。</p>
            <p class="text">4、三个报告均可同时发起助力，每个报告都可通过助力领取5折券或免费券，领取其中一种优惠券后此报告助力结束，不影响其它报告继续发起助力。</p>
            <p class="text">5、通过活动领取到的优惠券请前往 准了APP-我的-卡券中心 中查看使用，优惠券有效期7天，请尽快使用。</p>
            <p class="text">6、本活动最终解释权归准了所有。</p>
        </div>
        <div class="area-box invite-box">
            <div class="area-title" style="top: -1.19rem;">
                <span class="icon icon-friend"></span><span class="title-text">助力拿恋爱报告免费券</span>
            </div>
            <div class="help-list">
                <div class="help-list-item">
                    <div class="name">恋爱报告五折券</div>
                    <div class="nums">0/17</div>
                    <div class="btn event-btn" data-event="">立即领取</div>
                </div>
                <div class="help-list-item">
                    <div class="name">恋爱报告免费券</div>
                    <div class="nums">0/57</div>
                    <div class="btn disabled" data-event="">立即领取</div>
                </div>
            </div>
            <div class="btn large-btn event-btn" data-event="share" id="invite-btn" data-code="" data-name="恋爱报告" data-type="1">邀请好友助力</div>
            <hr class="hr">
            <div class="help-user-title">助力明细：</div>
            <div class="help-user-list">

            </div>
        </div>
        {/if}
    </div>
    <div class="foot"></div>
    <div id="dialog">
        <div class="mask event-btn" data-event="close-dialog"></div>
        <div class="dialog-content dialog-select">
            <div class="title">选择报告</div>
            <label class="label">恋爱报告<input class="radio" type="radio" name="id" value="1"></label>
            <label class="label">婚姻报告<input class="radio" type="radio" name="id" value="2"></label>
            <label class="label">合盘报告<input class="radio" type="radio" name="id" value="3"></label>
            <div class="tips">选择后不可进行更改</div>
            <div class="btn-box">
                <div class="cancle event-btn" data-event="close-dialog">取消</div>
                <div class="sure event-btn" data-event="sign">确定</div>
            </div>
        </div>
        <div class="dialog-content dialog-success">

        </div>
        <!--分享 0：微信；1：微信朋友圈；2：微博；3：qq；4：qq空间-->
        <div class="dialog-content share-choice">
            <div class="title">分享到：</div>
            <div class="share-list">
                <div class="list-item event-btn" data-event="share-invite" data-platform="0">
                    <span class="weixin"></span>微信
                </div>
                <div class="list-item event-btn" data-event="share-invite" data-platform="1">
                    <span class="weixin-timeline"></span>朋友圈
                </div>
                <div class="list-item event-btn" data-event="share-invite" data-platform="2">
                    <span class="weibo"></span>新浪微博
                </div>
                <div class="list-item event-btn" data-event="share-invite" data-platform="3">
                    <span class="qq"></span>QQ好友
                </div>
                <div class="list-item event-btn" data-event="share-invite" data-platform="4">
                    <span class="qzone"></span>QQ空间
                </div>
            </div>
        </div>
    </div>
</div>
<!--<script src="https://oss.goddessxzns.com/static/live/js/jquery-1.11.3.min.js"></script>-->
<script src="/static/astro_explain_new/js/jquery-1.11.3.min.js"></script>
{if !$is_in_app}
<script src="https://static.jmlk.co/scripts/dist/jmlink.min.js"></script>
{/if}
{include file="../apps/web/view/public/sensors.html" /}
<script>
    window.host = '{$domain}';
    window.isInApp = parseInt(`{$is_in_app}`);
    window.header = JSON.parse(`{$header}`);
    window.data = {
        status: 1, // 状态 0=>活动未开始 1=>活动进行中 2=>活动已结束
        sign_in_num: 0, // 已签到天数
        is_sign_in: 1, // 今天是否签到 0=>未签到 1=>已签到
        help_coupon: [
            // type 1=>恋爱 2=>婚姻 3=>合盘
            // name 恋爱报告｜婚姻报告｜合盘报告
            // help_num 已助力数
        ], // 助力信息
        give_coupon3: 0, // 领取第三天优惠券 0=>未领取 1=>已领取
        give_coupon5: 0, // 领取第五天优惠券 0=>未领取 1=>已领取
    };
    window.code = `{$code}`;
    window.shareCode = '';
    window.shareTypeText = '';
    window.shareType = 0;

    if (isInApp) {
        init();
    } else {
        var ua = navigator.userAgent.toLowerCase();
        var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
        if (!isAndroid) {
            new JMLink({
                jmlink: 'https://s0ue2y.jmlk.co/AA63',// 短链地址
                button: document.querySelector('#jmlink-btn'),
                plhparams: {
                    target: 'link',
                    link: window.host + '/web/active/valentine2022?need_auth=2&zhunle_not_show_nav=1&code=' + window.code
                },
                autoLaunchApp: false,
                downloadWhenUniversalLinkFailed: false,
                inapp: false,
            });
        }
    }

    // 初始化
    function init() {
        $.ajax({
            url: host + '/api/v33/active1/index',
            type: 'GET',
            timeout: 5000,
            dataType: 'json',
            headers: header,
            data: {},
            beforeSend: function () {
                resizeWindow();
            },
            success: function (res) {
                if (res.code === 200) {
                    window.data = res.data;
                    var progressItem = $('.progress-item');
                    window.data.sign_in_num = window.data.sign_in_num > 5 ? 5 : window.data.sign_in_num;
                    $('.progress').eq(0).attr({class: 'progress progress-' + window.data.sign_in_num});

                    // 签到次数 >= 5
                    if (window.data.sign_in_num >= 5) {
                        if (window.data.give_coupon5 < 1) {
                            progressItem.eq(4).find('.progress-btn').eq(0).text('领取').data('event', 'get-coupon');
                        } else {
                            progressItem.eq(4).find('.progress-btn').eq(0).addClass('disabled').text('已领取').data('event', '');
                        }
                    }
                    // 签到次数 >= 3天
                    if (window.data.sign_in_num >= 3) {
                        if (window.data.give_coupon3 < 1) {
                            progressItem.eq(2).find('.progress-btn').eq(0).text('领取').data('event', 'get-coupon');
                        } else {
                            progressItem.eq(2).find('.progress-btn').eq(0).addClass('disabled').text('已领取').data('event', '');
                        }
                    }

                    if (window.data.status < 1) {
                        $('#sign-btn').text('活动未开始').data('event', '').addClass('disabled');
                    } else if (window.data.status > 1) {
                        $('#sign-btn').text('活动已结束').data('event', '').addClass('disabled');
                    } else {
                        if (window.data.sign_in_num === 0) {
                            $('#sign-btn').text('签到抽取优惠券').data('event', 'sign0');
                        } else {
                            if (res.data.is_sign_in) {
                                // 签到最后一天
                                if (window.data.sign_in_num > 4) {
                                    $('#sign-btn').text('签到成功').data('event', 'sign').addClass('disabled');
                                } else {
                                    $('#sign-btn').text('签到成功，明日再来').data('event', 'sign').addClass('disabled');
                                }
                            } else {
                                $('#sign-btn').text('签到抽取优惠券').data('event', 'sign');
                            }
                        }
                    }

                    var htmlStr1 = '', htmlStr2 = '';
                    for (var i in window.data.help_coupon) {
                        var d = window.data.help_coupon[i];
                        var btnText = d['help_num'] ? ('助力' + d['help_num'] + '人') : '发起助力'
                        htmlStr1 += '<div class="title">' + d['name'] + '</div>';
                        if (d['status'] > 1) {
                            btnText = '活动已结束';
                            htmlStr2 += '<div class="invite-item"><div class="btn small-btn  event-btn disabled" data-event="invite" data-type="' + d['type'] + '">' + btnText + '</div></div>';
                        } else if (d['status'] < 1) {
                            btnText = '活动未开始';
                            htmlStr2 += '<div class="invite-item"><div class="btn small-btn  event-btn disabled" data-event="invite" data-type="' + d['type'] + '">' + btnText + '</div></div>';
                        } else {
                            htmlStr2 += '<div class="invite-item"><div class="btn small-btn  event-btn" data-event="invite" data-type="' + d['type'] + '">' + btnText + '</div></div>';
                        }
                    }
                    $('.title-list').eq(0).html(htmlStr1);
                    $('.btn-list').html(htmlStr2);

                    if (window.code.length > 0) {
                        // 确认帮助弹窗
                        dialogShow({
                            is_show: 1,
                            type: 'help-confirm',
                            data: {
                                code: window.code
                            },
                        });
                    }
                    // 神策打点
                    sensors.track('ValentineView2022', {});
                } else {
                    toast(res.msg);
                }
            },
            error: function () {
                toast('数据获取失败，稍后尝试～');
            },
            complete: function (XMLHttpRequest, status) {

            }
        })
    }

    $(window).resize(function () {
        resizeWindow();
    })

    function resizeWindow() {
        if ($(window).width() >= 750) {
            $('html').css({'font-size': '32px'});
        } else {
            $('html').css({'font-size': '4.267vw'});
        }
    }

    /**
     * 弹窗展示
     * data
     *  type
     *  is_show 0=>隐藏,1=>显示
     *  data 数据
     */
    function dialogShow(data) {
        $('#dialog').hide().find('.dialog-content').hide().siblings('.mask').hide();
        switch (data.is_show) {
            case 1:
                var htmlStr = '';
                switch (data.type) {
                    case 'select':
                        var dialogSelect = $('.dialog-select');
                        dialogSelect.siblings('.mask').show();
                        dialogSelect.show().parent().show();
                        break;
                    case 'success':
                        var dialogSuccess = $('.dialog-success');
                        switch (data.data.num) {
                            case 3:
                                htmlStr += '<div class="title" style="background-image: url(/static/active/valentine2022/img/sign3-title-bg.png)"></div>' +
                                    '  <div class="content content-img">' +
                                    '    <div class="name">' + data.data.name + '</div>' +
                                    '    <div class="d-title">' + data.data.desc + '</div>' +
                                    '    <div class="d-des">请通过准了APP我的卡券查看使用</div>' +
                                    '  </div>' +
                                    '  <div class="tips">已将优惠券发放至准了APP“卡券中心”</div>' +
                                    '  <div class="btn-box">' +
                                    '    <div class="cancle event-btn" data-event="close-dialog">取消</div>' +
                                    '    <div class="sure event-btn" data-event="common-js-to-native" data-target="local" data-link="discount_coupon_center?need_auth=2">去使用</div>' +
                                    '  </div>';
                                break;
                            case 5:
                                htmlStr += '<div class="title" style="background-image: url(/static/active/valentine2022/img/sign5-title-bg.png)"></div>' +
                                    '  <div class="content content-img">' +
                                    '    <div class="name">' + data.data.name + '</div>' +
                                    '    <div class="d-title">' + data.data.desc + '</div>' +
                                    '    <div class="d-des">请通过准了APP我的卡券查看使用</div>' +
                                    '  </div>' +
                                    '  <div class="tips">已将优惠券发放至准了APP“卡券中心”</div>' +
                                    '  <div class="btn-box">' +
                                    '    <div class="cancle event-btn" data-event="close-dialog">取消</div>' +
                                    '    <div class="sure event-btn" data-event="common-js-to-native" data-target="local" data-link="discount_coupon_center?need_auth=2">去使用</div>' +
                                    '  </div>';
                                break;
                            default:
                                htmlStr += '<div class="title" style="background-image: url(/static/active/valentine2022/img/success-title-bg.png)"></div>' +
                                    '  <div class="content content-img">' +
                                    '    <div class="name">' + data.data.name + '</div>' +
                                    '    <div class="d-title">' + data.data.desc + '</div>' +
                                    '    <div class="d-des">请通过准了APP我的卡券查看使用</div>' +
                                    '  </div>' +
                                    '  <div class="tips">已将优惠券发放至准了APP“卡券中心”</div>' +
                                    '  <div class="btn-box">' +
                                    '    <div class="cancle event-btn" data-event="close-dialog">取消</div>' +
                                    '    <div class="sure event-btn" data-event="common-js-to-native" data-target="local" data-link="discount_coupon_center?need_auth=2">去使用</div>' +
                                    '  </div>';
                                break;
                        }
                        dialogSuccess.html(htmlStr);
                        dialogSuccess.siblings('.mask').show();
                        dialogSuccess.show().parent().show();
                        break;
                    case 'show':
                        var showSuccess = $('.dialog-success');
                        console.log('data:', data)
                        console.log('data.data.day:', data.data.day)
                        switch (data.data.day) {
                            case 3:
                                htmlStr += '<div class="title" style="background-image: url(/static/active/valentine2022/img/sign3-title-bg.png)"></div>' +
                                    '  <div class="content content-text">' +
                                    '    <p class="text">年运免费优惠券</p>' +
                                    '    <p class="text">年运5折优惠券</p>' +
                                    '    <p class="text">年运77折优惠券</p>' +
                                    '  </div>' +
                                    '  <div class="tips">从以上三种优惠券中随机抽取一张发放</div>' +
                                    '  <div class="btn-box">' +
                                    '    <div class="cancle know event-btn" data-event="close-dialog">知道了</div>' +
                                    '  </div>';
                                break;
                            case 5:
                                htmlStr += '<div class="title" style="background-image: url(/static/active/valentine2022/img/sign5-title-bg.png)"></div>' +
                                    '  <div class="content content-text">' +
                                    '    <p class="text">一生报告免费优惠券</p>' +
                                    '    <p class="text">一生报告5折优惠券</p>' +
                                    '    <p class="text">一生报告77折优惠券</p>' +
                                    '  </div>' +
                                    '  <div class="tips">从以上三种优惠券中随机抽取一张发放</div>' +
                                    '  <div class="btn-box">' +
                                    '    <div class="cancle know event-btn" data-event="close-dialog">知道了</div>' +
                                    '  </div>';
                                break;
                        }
                        showSuccess.html(htmlStr);
                        showSuccess.siblings('.mask').show();
                        showSuccess.show().parent().show();
                        break;
                    case 'confirm':
                        var dialogSuccess = $('.dialog-success');
                        htmlStr += '' +
                            '  <div class="content content-text" style="margin-top: 2rem">' +
                            '    <p class="text" style="text-align: left">确认要领取恋爱报告五折券吗，领取后此报告助力活动结束，可继续助力其它报告活动。</p>' +
                            '  </div>' +
                            '  <div class="btn-box">' +
                            '    <div class="cancle event-btn" data-event="close-dialog">取消</div>' +
                            '    <div class="sure event-btn" data-event="getHelpCoupon">确定</div>' +
                            '  </div>';
                        dialogSuccess.html(htmlStr);
                        dialogSuccess.siblings('.mask').show();
                        dialogSuccess.show().parent().show();
                        break;
                    case 'show-copy':
                        var dialogSuccess = $('.dialog-success');
                        htmlStr += '<div class="title" style="background-image: url(/static/active/valentine2022/img/copy-title-bg.png);width: 11.94rem;height: 3.19rem;"></div>' +
                            '  <div class="content content-text">' +
                            '    <p class="text" style="-webkit-user-select: text;user-select: text;margin-bottom: 2.15rem;">' + data.data.code + '</p>' +
                            '  </div>' +
                            '  <div class="btn-box">' +
                            '    <div class="cancle event-btn" data-event="close-dialog">取消</div>' +
                            '    <div class="sure event-btn" data-event="copy" data-text="' + data.data.code + '">点击复制</div>' +
                            '  </div>';
                        dialogSuccess.html(htmlStr);
                        dialogSuccess.siblings('.mask').show();
                        dialogSuccess.show().parent().show();
                        break;
                    // 展示帮助好友助力确认弹窗
                    case 'help-confirm':
                        var dialogSuccess = $('.dialog-success');
                        htmlStr += '<div class="title" style="background-image: url(/static/active/valentine2022/img/help-title-bg.png);width: 8.69rem; height: 1.44rem;"></div>' +
                            '  <div class="content content-text" style="margin-top: 2rem">' +
                            '    <p class="text" style="text-align: left">每天只有一次助力资格哦～确定要帮好友助力吗？</p>' +
                            '  </div>' +
                            '  <div class="btn-box">' +
                            '    <div class="cancle event-btn" data-event="close-dialog">取消</div>' +
                            '    <div class="sure event-btn" data-event="help-request" data-code="' + data.data.code + '">帮TA助力</div>' +
                            '  </div>';
                        dialogSuccess.html(htmlStr);
                        dialogSuccess.siblings('.mask').show();
                        dialogSuccess.show().parent().show();
                        break;
                    case 'share-show':
                        var shareWindow = $('.share-choice');
                        shareWindow.siblings('.mask').show();
                        shareWindow.show().parent().show();
                        break;
                }
                break;
        }
        return true;
    }

    /**
     * 绑定页面通用点击事件
     * 按钮元素必须包含类名：event-btn
     * 按钮元素必须包含属性：data-event  值为要触发的事件
     * 例如：<div class="event-btn" data-event="sign">签到</div>，表示触发签到事件
     */
    $('.container').on('click', '.event-btn', function () {
        var obj = $(this), event = obj.data('event');
        switch (event) {
            // 展示优惠券类型选择
            case 'sign0':
                dialogShow({
                    is_show: 1,
                    type: 'select',
                    data: {},
                });
                // $('#dialog').show().find('.mask').show().siblings('.dialog-select').show();
                break;
            // 签到
            case 'sign':
                var param = {}
                // 首次签到时，选择优惠券
                if (window.data.sign_in_num === 0) {
                    param['type'] = parseInt($('.dialog-select [name=id]:checked').val());
                    if (isNaN(param['type']) || param['type'] <= 0 || param['type'] > 3) {
                        toast('请先选择优惠券类型');
                        return false;
                    }
                }
                $.ajax({
                    url: host + '/api/v33/active1/sign_in',
                    type: 'POST',
                    timeout: 5000,
                    dataType: 'json',
                    headers: header,
                    data: param,
                    beforeSend: function () {
                    },
                    success: function (res) {
                        if (res.code === 200) {
                            var signBtnDom = $('#sign-btn');
                            signBtnDom.addClass('disabled');
                            if (window.data.sign_in_num >= 4) {
                                // 签到最后一天
                                signBtnDom.text('签到成功').data('event', '');
                            } else {
                                signBtnDom.text('签到成功，明日再来').data('event', 'sign');
                            }
                            window.data.sign_in_num++;
                            if (window.data.sign_in_num > 5) {
                                window.data.sign_in_num = 5;
                            }
                            // 进度条变化
                            $('.progress').attr('class', 'progress progress-' + window.data.sign_in_num);

                            var progressItem = $('.progress-item');

                            // 签到次数 >= 5
                            if (window.data.sign_in_num >= 5) {
                                if (window.data.give_coupon5 < 1) {
                                    progressItem.eq(4).find('.progress-btn').eq(0).text('领取').data('event', 'get-coupon');
                                }
                            }// 签到次数 >= 3天
                            if (window.data.sign_in_num >= 3) {
                                if (window.data.give_coupon3 < 1) {
                                    progressItem.eq(2).find('.progress-btn').eq(0).text('领取').data('event', 'get-coupon');
                                }
                            }

                            if (res.data['coupon_info']) {
                                // 签到成功，弹窗提示
                                dialogShow({
                                    is_show: 1,
                                    type: 'success',
                                    data: {
                                        name: res.data['coupon_info']['name'],
                                        desc: res.data['coupon_info']['desc']
                                    },
                                })
                            }
                        } else {
                            toast(res.msg);
                        }
                    },
                    error: function () {
                        toast('数据获取失败，稍后尝试～');
                    },
                    complete: function (XMLHttpRequest, status) {

                    }
                })
                break;
            // 展示累计签到礼
            case 'show':
                dialogShow({
                    is_show: 1,
                    type: 'show',
                    data: {
                        day: parseInt(obj.data('day'))
                    },
                });
                break;
            // APP跳转
            case 'common-js-to-native':
                var target = obj.data('target'), link = obj.data('link');
                console.log(target, link)
                if (!target) return;
                try {
                    window.webkit.messageHandlers.commonJsToNative.postMessage({
                        'target': target,
                        'link': link,
                    });
                } catch (e1) {
                    try {
                        androidwebview.commonJsToNative(target, link)
                    } catch (e2) {
                        if (target === 'link') {
                            window.location.href = link;
                        } else {
                            console.log('跳转不支持', 'target:', target, 'link:', link);
                        }
                    }
                }
                break;
            // 关闭弹窗
            case 'close-dialog':
                $('#dialog .dialog-select').hide().siblings('.mask').hide().parent().hide();
                break;
            // 发起助力
            case 'invite':
                var type = parseInt($(this).data('type'));
                // 获取数据
                $.ajax({
                    url: host + '/api/v33/active1/get_help_detail',
                    type: 'GET',
                    timeout: 5000,
                    dataType: 'json',
                    headers: header,
                    data: {type: type},
                    beforeSend: function () {
                    },
                    success: function (res) {
                        console.log('发起助力：', res)
                        if (res.code === 200) {
                            var htmlStr1 = '', htmlStr2 = '';
                            $.each(res.data['coupon_info'], function (k, v) {
                                htmlStr1 += '<div class="help-list-item">';
                                htmlStr1 += ' <div class="name">' + v['name'] + '</div>';
                                htmlStr1 += ' <div class="nums">' + res.data['help_num'] + '/' + v['help_num'] + '</div>';
                                if (v['status'] === 1) {
                                    htmlStr1 += ' <div class="btn disabled" data-id="' + v['id'] + '">已领取</div>';
                                } else if (res.data['help_num'] < v['help_num']) {
                                    htmlStr1 += ' <div class="btn disabled" data-id="' + v['id'] + '">立即领取</div>';
                                } else {
                                    htmlStr1 += ' <div class="btn event-btn" data-event="get-help-coupon" data-id="' + v['id'] + '">立即领取</div>';
                                }
                                htmlStr1 += '</div>';
                            })
                            $('.invite-box .help-list').html(htmlStr1);

                            if (res.data['help_list'].length > 0) {
                                $.each(res.data['help_list'], function (k, v) {
                                    htmlStr2 += '<p class="help-item">' + v + '</p>';
                                })
                            } else {
                                htmlStr2 += '<p class="help-item">暂无好友助力</p>';
                            }
                            $('.invite-box .help-user-list').html(htmlStr2);

                            if (res.data['status'] < 1) {
                                $('#invite-btn').addClass('disabled').data('event', '').text('活动未开始');
                            } else if (res.data['status'] > 1) {
                                $('#invite-btn').addClass('disabled').data('event', '').text('活动已结束');
                            } else {
                                $('#invite-btn').data('event', 'share').data('code', res.data['help_id']).data('type', type);
                            }

                            $('.index-box').hide();
                            $('.invite-box').show();
                            var coupon_type = '';
                            switch (type) {
                                case 1:
                                    coupon_type = '恋爱';
                                    break;
                                case 2:
                                    coupon_type = '婚姻';
                                    break;
                                case 3:
                                    coupon_type = '合盘';
                                    break;
                            }
                            // 神策打点 1=>恋爱 2=>婚姻 3=>合盘
                            sensors.track('ValentineHelpView2022', {
                                coupon_type: coupon_type
                            });
                        } else {
                            toast(res.msg)
                        }
                    },
                    error: function () {
                        toast('数据获取失败，稍后尝试～');
                    },
                    complete: function (XMLHttpRequest, status) {

                    }
                })
                break;
            // 帮Ta助力
            case 'help':
                var codeDom = $('#code'), help_id = codeDom.val().trim();
                if (help_id.length === 0) {
                    codeDom.focus();
                    toast('请先填写邀请码');
                    return false;
                }
                // 确认帮助弹窗
                dialogShow({
                    is_show: 1,
                    type: 'help-confirm',
                    data: {
                        code: help_id
                    },
                });
                break;
            case 'help-request':
                var code = obj.data('code').trim();
                if (code.length === 0) {
                    toast('请先填写邀请码');
                    return false;
                }
                $.ajax({
                    url: host + '/api/v33/active1/help_user',
                    type: 'POST',
                    timeout: 5000,
                    dataType: 'json',
                    headers: header,
                    data: {help_id: code},
                    beforeSend: function () {
                    },
                    success: function (res) {
                        toast(res.msg);
                        // 关闭确认助力弹窗
                        dialogShow({
                            is_show: 0,
                            type: 'help-confirm',
                            data: {},
                        });
                    },
                    error: function () {
                        toast('数据获取失败，稍后尝试～');
                    },
                    complete: function (XMLHttpRequest, status) {

                    }
                })
                break;
            // 邀请好友助力
            case 'share':
                var code = $(this).data('code'), type = parseInt($(this).data('type'));
                window.shareCode = code;
                switch (type) {
                    case 2:
                        window.shareTypeText = '婚姻报告';
                        break;
                    case 3:
                        window.shareTypeText = '合盘报告';
                        break;
                    default:
                        window.shareTypeText = '恋爱报告';
                        break;
                }
                window.shareType = type
                dialogShow({
                    is_show: 1,
                    type: 'share-show',
                    data: {},
                });
                break;
            case 'share-invite':
                var title = '帮我点一下，助我免费查看' + window.shareTypeText + '！',
                    desc = '距离我免费查看' + window.shareTypeText + '，只差你的一个助力了！',
                    url = host + '/web/active/valentine2022?need_auth=2&code=' + window.shareCode + '&type=' + window.shareType,
                    platform = parseInt($(this).data('platform'));
                try {
                    window.webkit.messageHandlers.commonJsToNativeShare.postMessage({
                        title: title,
                        desc: desc,
                        url: url,
                        platform: platform
                    });
                    var coupon_type = '';
                    switch (window.shareType) {
                        case 1:
                            coupon_type = '恋爱';
                            break;
                        case 2:
                            coupon_type = '婚姻';
                            break;
                        case 3:
                            coupon_type = '合盘';
                            break;
                    }
                    sensors.track('ValentineHelpInvite2022', {
                        coupon_type: coupon_type
                    });
                } catch (e1) {
                    try {
                        androidwebview.commonJsToNativeShare(title, desc, url, platform);
                    } catch (e2) {
                        console.log('调用失败', e1, e2);
                    }
                }
                break;
            // 活动页面分享
            case 'share-page':
                var title = '专属你的七夕好运来了',
                    desc = '距离我免费查看',
                    url = host + '/web/active/valentine2022?need_auth=2',
                    platform = 5
                try {
                    window.webkit.messageHandlers.commonJsToNativeShare.postMessage({
                        title: title,
                        desc: desc,
                        url: url,
                        platform: platform
                    });
                } catch (e1) {
                    try {
                        androidwebview.commonJsToNativeShare(title, desc, url, platform);
                    } catch (e2) {
                        console.log('调用失败', e1, e2);
                    }
                }
                break;
            // 展示复制弹窗
            case 'show-copy':
                var code = $(this).data('code');
                dialogShow({
                    is_show: 1,
                    type: 'show-copy',
                    data: {
                        code: code
                    },
                });
                break;
            // 复制操作
            case 'copy':
                try {
                    console.log('copyToClip:', copyToClip($(this).data('text')))
                    toast('复制成功')
                } catch (e) {
                    console.log('复制失败：', e)
                    toast('复制失败')
                }
                break;
            // 领取累计签到优惠券
            case 'get-coupon':
                var day = parseInt(obj.data('day'));
                // 获取数据
                $.ajax({
                    url: host + '/api/v33/active1/get_sign_in_coupon',
                    type: 'GET',
                    timeout: 5000,
                    dataType: 'json',
                    headers: header,
                    data: {day: day},
                    beforeSend: function () {
                    },
                    success: function (res) {
                        if (res.code === 200) {
                            dialogShow({
                                is_show: 1,
                                type: 'success',
                                data: {
                                    name: res.data['coupon_info']['name'],
                                    desc: res.data['coupon_info']['desc'],
                                    num: day,
                                },
                            })
                            obj.text('已领取').data('event', '').addClass('disabled');
                        } else {
                            toast(res.msg);
                        }
                    },
                    error: function () {
                        toast('数据获取失败，稍后尝试～');
                    },
                    complete: function (XMLHttpRequest, status) {

                    }
                })
                break;
            // 领取助力成功优惠券
            case 'get-help-coupon':
                var id = parseInt($(this).data('id'));
                // 获取数据
                $.ajax({
                    url: host + '/api/v33/active1/get_help_coupon',
                    type: 'GET',
                    timeout: 5000,
                    dataType: 'json',
                    headers: header,
                    data: {id: id},
                    beforeSend: function () {
                    },
                    success: function (res) {
                        console.log('领取优惠券：', res)
                        if (res.code === 200) {
                            // 按钮状态变更
                            obj.removeClass('event-btn').addClass('disabled').text('已领取');
                            $('#invite-btn').addClass('disabled').data('event', '').text('活动已结束');
                            // 弹窗提示
                            dialogShow({
                                is_show: 1,
                                type: 'success',
                                data: {
                                    name: res.data['coupon_info']['name'],
                                    desc: res.data['coupon_info']['desc']
                                },
                            })
                        } else {
                            toast(res.msg)
                        }
                    },
                    error: function () {
                        toast('数据获取失败，稍后尝试～');
                    },
                    complete: function (XMLHttpRequest, status) {

                    }
                })
                break;
        }
        return false;
    })

    // 返回
    $('#nav .to-back').click(function () {
        var indexBox = $('.index-box');
        if (indexBox.is(':visible')) {
            try {
                window.webkit.messageHandlers.commonJsToNative.postMessage({
                    'target': 'local',
                    'link': 'back',
                });
            } catch (e1) {
                try {
                    androidwebview.commonJsToNative('local', 'back');
                } catch (e2) {
                    console.log('调用失败', e1, e2);
                }
            }
        } else {
            indexBox.show();
            $('.invite-box').hide();
        }
    })

    /**
     * 提示信息
     * @param msg
     */
    function toast(msg) {
        var m = document.createElement('div');
        m.innerHTML = msg;
        m.style.cssText = 'color: #ffffff;background: rgba(0,0,0,0.7);width: 66%;line-height: 2.5rem;text-align: center;border-radius: 0.25rem;position: fixed;top: 50%;left: calc(17% - 16px);z-index: 999999;font-size: 1rem;padding: 0 16px; margin-top: -1.25rem';
        document.body.appendChild(m);
        setTimeout(function () {
            document.body.removeChild(m);
        }, 2500);
    }

    // 复制到剪切板
    function copyToClip(content) {
        var copy = document.createElement("input");
        copy.setAttribute("value", content);
        document.body.appendChild(copy);
        copy.select();
        var r = document.execCommand("copy");
        document.body.removeChild(copy);
        return r;
    }
</script>
</body>
</html>
